let ParentId = 0
function  Parent(name, actions) {
  this.name = name
  this.actions = actions
  ParentId++
  // if (!name){
    console.log('Parent id',ParentId)
  // }
}

Parent.prototype.eat = function(){
  console.log(this.name)
}
Parent.prototype.getName = function(){
  console.log(this.name)
}

function Child(id,...args) {
  Parent.apply(this,args)
  this.id = id
}

// Child.prototype = new Parent()

// 1.temp构造函数
// let TempId = 0
// function TempFunction () {
//   TempId++
//   console.log('TempFunction id',TempId)
// }
// TempFunction.prototype = Parent.prototype
// Child.prototype = new TempFunction()

// 2.Object.create
Child.prototype = Object.create(Parent.prototype)

// 为甚不用 Child.prototype = Parent.prototype 因为直接赋值  引用类型  修改了子原型 会更改父原型 所以需要中间想法隔一层

Child.prototype.constuctor = Child


const child1 = new Child(1,'lulu',['1111'])
const child2 = new Child(2,'xiaoming',['4444','555'])
const child3 = new Child(3,'xiaoming3',['3333333333','33333333333333333'])

child1.actions.push('333')
console.log(child1.actions)
console.log(child2.actions)
console.log(child1.eat === child2.eat) // true

child1.getName()
child2.getName()